<template>
  <a-drawer
    :maskClosable="false"
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
<!--    @unButtonDisable="unButtonDisable"-->
    <erp-achievements-extraction-dt-form
      ref="realForm"
      @ok="submitCallback"
      @dataOne="dataOne"
      @getDataSources="getDataSources"
      :disabled="disableSubmit"
      normal></erp-achievements-extraction-dt-form>
    <div class="drawer-footer">
      <a-popconfirm title="确定关闭弹窗吗?" @confirm="handleCancel" :getPopupContainer="(node) =>  node.parentNode">
        <a-button style="margin-bottom: 0;">关闭</a-button>
      </a-popconfirm>
<!--      :disabled="buttonDisable" -->
      <a-button v-if="!disableSubmit"  @click="handleOk"   type="primary" style="margin-bottom: 0;">保存</a-button>
    </div>
  </a-drawer>
</template>

<script>

  import ErpAchievementsExtractionDtForm from './ErpAchievementsExtractionDtForm'

  export default {
    name: 'ErpAchievementsExtractionDtModal',
    components: {
      ErpAchievementsExtractionDtForm
    },
    props:['dataSource'],
    data () {
      return {
        title:"操作",
        width:800,
        visible: false,
        // buttonDisable:false,//2022-12-05 新增保存按钮重复点击限制
        disableSubmit: false
      }
    },
    methods: {
      add () {
        // this.buttonDisable = false
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.realForm.flag = true
          this.$refs.realForm.add();
        })
      },
      edit (record) {
        // this.buttonDisable = false
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.realForm.flag = false
          this.$refs.realForm.edit(record);
        });
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      submitCallback(data, flag){


        // let dataSources = this.getDataSources()

        //过滤出子表中已存在符合条件的的数据
        if (this.dataSource && this.dataSource.length > 0){
          //排除自己并且条件符合
          let temp = this.dataSource.filter(item => data.id !== item.id &&  item.projectId === data.projectId && item.taskId === data.taskId && item.feeTeamId === data.feeTeamId);
          if (temp.length > 0){
            this.$message.warning('请勿选择重复的项目名称、任务名称以及费用所属团队！');
            return
          }

          //过滤出排除自己的
          let temp2 = this.dataSource.filter(item => data.id !== item.id &&  item.feeTeamId !== data.feeTeamId);
          if (temp2.length > 0){
            this.$message.warning('所选的费用所属团队需要一致！')
            return;
          }
        }


        this.$emit('dataOne', data, flag);
        this.visible = false;
      },
      // unButtonDisable () {
      //   this.buttonDisable = false
      // },
      //获取子表数据列表
      getDataSources(){
        return  this.$emit('submitForm');
      },
      handleOk () {
        // this.buttonDisable = true
        this.$refs.realForm.submitForm();
      },
      handleCancel () {
        this.close()
      },
      dataOne(data) {
        this.$emit('dataOne', data);
      }
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
  .drawer-footer{
    position: absolute;
    bottom: -8px;
    width: 100%;
    border-top: 1px solid #e8e8e8;
    padding: 10px 16px;
    text-align: right;
    left: 0;
    background: #fff;
    border-radius: 0 0 2px 2px;
    z-index:9999999
  }
</style>
